
package com.updesignsz.admin.controller;

import com.updesignsz.admin.service.TypeService;
import com.updesignsz.admin.util.ResponseUtil;
import com.updesignsz.admin.vo.form.TypeForm;
import com.updesignsz.commom.entity.Type;
import com.updesignsz.commom.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 项目类型
 * Creation date 2020-8-8 17:53:48
 */
@RestController
public class TypeController  {

	@Autowired
	private TypeService typeService;

    /**
     * 项目类型列表
     */
    @GetMapping("/type")
    public void insuranceType(Type type, HttpServletResponse response) {
        ResultVo vo = new ResultVo();
        vo.setData(typeService.listAll(type));
        ResponseUtil.outJson(vo.toJsonMsg(), response);
    }

    /**
     * 保存 项目类型
     */
    @PostMapping("/type")
    public void addType(@Validated(PostMapping.class) @RequestBody TypeForm form, HttpServletResponse response) {
        ResultVo vo = new ResultVo();
        typeService.saveType(form);
        vo.setData(typeService.getById(form.getId()));
        ResponseUtil.outJson(vo.toJsonMsg(), response);
    }


    /**
     * 删除 项目类型
     */
    @DeleteMapping("/type/{typeId}")
    public void deleteType(@PathVariable Integer typeId, HttpServletResponse response) {
        ResultVo vo = new ResultVo();
        typeService.deleteType(typeId);
        ResponseUtil.outJson(vo.toJsonMsg(), response);
    }

    /**
     * 修改 项目类型
     */
    @PutMapping("/type")
    public void updateType(@Validated(PutMapping.class) @RequestBody TypeForm form, HttpServletResponse response) {
        ResultVo vo = new ResultVo();
        typeService.updateType(form);
        vo.setData(typeService.getById(form.getId()));
        ResponseUtil.outJson(vo.toJsonMsg(), response);
    }
}